package com.ziqi.hututubackend.exception;

import com.ziqi.hututubackend.common.BaseResponse;
import com.ziqi.hututubackend.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExcetionHandler {

        @ExceptionHandler(BusinessException.class)
        public BaseResponse<?> businessExceptionHandler(BusinessException e) {
            log.error("BusinessException", e);
            return ResultUtils.error(e.getCode(), e.getMessage());
        }

        @ExceptionHandler(RuntimeException.class)
        public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
            log.error("RuntimeException", e);
            return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误");
        }

}
